package com.briup.jd2511.web03.exception;

import com.briup.jd2511.web03.util.Result;
import com.briup.jd2511.web03.util.ResultCode;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局的异常处理
 */
//@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Object handleException(Exception e){
        Result result = null;
        if(e instanceof ServiceException se){
            result = Result.error(se.getResultCode());
        }else{
            // 返回500
            result = Result.error(ResultCode.FAILURE);
        }
        return result;
    }
}
